﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class AddAccessoryDetailDAL
    {

        #region[AddAccessoryDetail_SelectALL]
        public List<DTO.AddAccessoryDetailDTO> AddAccessoryDetail_SelectALL()
        {
            List<DTO.AddAccessoryDetailDTO> aadall = new List<DTO.AddAccessoryDetailDTO>();
            
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("SelectAllAddAccessoryDetail", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            con.Open();
            MySqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                DTO.AddAccessoryDetailDTO aad = new DTO.AddAccessoryDetailDTO();
                aad.AddAccessoryID = dr.GetInt32(0);
                aad.AccessoryId = dr.GetInt32(1);
                aad.Number = dr.GetInt32(2);
                aad.PrizeAdd = dr.GetInt32(3);
                aad.AddID = dr.GetInt32(4);
                aadall.Add(aad);
            }
            dr.Close();
            con.Close();

            return aadall;
        }
        #endregion

        #region [AddAccessoryDetail_Insert]
        public bool AddAccessoryDetail_Insert(DTO.AddAccessoryDetailDTO aad)
        {
            Connection connecttion = new Connection();
            MySqlConnection con = new MySqlConnection(connecttion.Connect);
            MySqlCommand cmd = new MySqlCommand("AddAddAccessoryDetail", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new MySqlParameter("@accessoryid", aad.AccessoryId));
            cmd.Parameters.Add(new MySqlParameter("@number", aad.Number));
            cmd.Parameters.Add(new MySqlParameter("@prizeadd", aad.PrizeAdd));
            cmd.Parameters.Add(new MySqlParameter("@addid", aad.AddID));

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            return true;
        }
        #endregion

    }
}
